import Vue from 'vue'
import VueRouter from 'vue-router'

const App = resolve => require(['../App.vue'], resolve);
const Login = resolve => require(['@/components/Login.vue'], resolve);
const Main = resolve => require(['@/components/main/main.vue'], resolve);
const NotFound = resolve => require(['@/components/404.vue'], resolve);

//关于
const About = resolve => require(['@/components/about/main.vue'], resolve);

//首页
const HomePage = resolve => require(['@/module/Home/HomePage.vue'], resolve);

//测试markdown
const markdownTest = resolve => require(['@/module/Test/markdownTest.vue'], resolve);

//Article
const ArticleList = resolve => require(['@/module/Article/ArticleList.vue'], resolve);
const ArticleEdit = resolve => require(['@/module/Article/ArticleEdit.vue'], resolve);
const ArticleCreate = resolve => require(['@/module/Article/ArticleCreate.vue'], resolve);


//Nav1
const Page1 = resolve => require(['@/module/Nav1/Page1.vue'], resolve);
const PersonList = resolve => require(['@/module/Nav1/PersonList.vue'], resolve);

const Page3 = resolve => require(['@/module/Nav3/Page.vue'], resolve);
const test = resolve => require(['@/module/Nav3/test.vue'], resolve);

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/',
      name: 'login',
      meta: { keepAlive: true },
      hidden: true,
      component: Login
    },
    {
      path: '/404',
      name: '404',
      hidden: true,
      component: NotFound
    },
    {
      path: '/home',
      component: Main,
      name: '首页',
      onlyone:true,
      iconCls: 'el-icon-location',
      children: [
        { path: '/home', name: 'home', meta: { keepAlive: true }, component: HomePage },

      ]
    },
    {
      path: '/',
      onlyone:false,
      redirect: { name: 'home' },
      component: Main,
      name: '博文',
      iconCls: 'el-icon-menu',
      children: [
        { path: '/ArticleList', name: '博文', meta: { keepAlive: true }, component: ArticleList },
        { path: '/ArticleEdit/:id', name: '博文', meta: { keepAlive: true }, component: ArticleEdit ,hidden:true },
        { path: '/ArticleCreate', name: '博文', meta: { keepAlive: true }, component: ArticleCreate ,hidden:true},
        { path: '/Page1', name: '页面1', meta: { keepAlive: true }, component: Page1 },
        { path: '/PersonList', name: '人员信息',  component: PersonList },
        { path: '/Page3', name: 'Page',  component: Page3 },
        { path: '/test', name: '测试页', meta: { keepAlive: true }, component: test },
        { path: '/markdownTest', name: 'MarkDown', meta: { keepAlive: true }, component: markdownTest },
      ]
    },
    {
      path: '/about',
      component: Main,
      name: '关于',
      onlyone:true,
      iconCls: 'el-icon-location',
      children: [
        { path: '/about', name: 'about', meta: { keepAlive: true }, component: About },

      ]
    },
  ]
})

// router.beforeEach((to, from, next) => {
//   if (to.name === "login") {
//     next();
//     return;
//   }

//   guardRoute(to, from, next);
// });

function guardRoute(to, from, next) {
  if (to.name === 'home') {
    next({
      name: 'login'
    });
  } else {
    next({
      name: 'login',
      query: {
        redirect: to.fullPath
      }
    });
  }
}


export default router;